<template>
	<view class="pages">
		<!-- 头部导航 -->
		 <uni-nav-bar left-icon="left"    :statusBar="true" titleSize="30px" leftText="返回" right-text="提交"   title="修改物流信息"  @clickLeft="back" @clickRight="btnOk"  :fixed="true" backgroundColor="#3286ed" color="#fff"/>
		
		<u--form class="form" labelPosition="left" labelWidth="100px" :model="addlogisticForm" ref="form">
			<u-form-item  label="出库单编号" prop="orderNo" borderBottom ref="item1"  >
				<u--input :readonly="true" v-model="addlogisticForm.orderNo" border="none" placeholder="租赁订单"></u--input>
			</u-form-item>
			<u-form-item  label="出入库类型" prop="orderProperty" borderBottom ref="item1"  >
				 <u-text v-if="addlogisticForm.orderProperty==1" text="出库"></u-text>
				 <u-text v-if="addlogisticForm.orderProperty==2" text="入库"></u-text>
				  <u-text v-if="addlogisticForm.orderProperty==3" text="调拨"></u-text>
			</u-form-item>
			<u-form-item  label="发货仓库名" prop="warehouseName" borderBottom ref="item1"  >
				<u--input :readonly="true" v-model="addlogisticForm.warehouseName" border="none" placeholder="对接人"></u--input>
			</u-form-item>
			<u-form-item  label="运输方式" prop="shippingType" borderBottom ref="item1"  >
				<u-text v-if="addlogisticForm.shippingType=='0'" text="快递"></u-text>
				<u-text v-if="addlogisticForm.shippingType=='1'" text="物流"></u-text>
				<u-text v-if="addlogisticForm.shippingType=='2'" text="自提"></u-text>
				<u-text v-if="addlogisticForm.shippingType=='3'" text="专车"></u-text>
			</u-form-item>
			 <!-- <u-form-item  label="对接人" prop="consigneeName" borderBottom ref="item1"  >
			 	<u--input :readonly="true" v-model="addlogisticForm.consigneeName" border="none" placeholder="对接人"></u--input>
			 </u-form-item>
			 <u-form-item  label="对接人电话" prop="consigneeTel" borderBottom ref="item1"  >
			 	<u--input :readonly="true" v-model="addlogisticForm.consigneeTel" border="none" placeholder="对接人电话"></u--input>
			 </u-form-item> -->
			<u-form-item  label="司机名称" prop="driverName" borderBottom ref="item1">
				<u--input v-model="addlogisticForm.driverName" border="none" placeholder="请输入司机名称"></u--input>
			</u-form-item>
			
			<u-form-item  label="司机联系方式" prop="driverTel" borderBottom ref="item1">
				<u--input v-model="addlogisticForm.driverTel" border="none" placeholder="司机联系方式"></u--input>
			</u-form-item>
			<u-form-item  label="车辆信息" prop="vehicleInformation" borderBottom ref="item1">
				<u--input v-model="addlogisticForm.vehicleInformation" border="none" placeholder="车辆信息"></u--input>
			</u-form-item>
			<!-- <u-form-item  label="项目地址" prop="projectAddress" borderBottom ref="item1">
				<u--text :text="addlogisticForm.projectAddress" border="none" placeholder="请输入司机名称"></u--text>
			</u-form-item> -->
			<u-form-item  label="物流费用" prop="logisticsExpenses" borderBottom ref="item1">
				<u--input v-model="addlogisticForm.logisticsExpenses" border="none" placeholder="物流费用"></u--input>
			</u-form-item>
			<u-form-item   label="到货日期" prop="arrivalDate" borderBottom ref="item1">
				<u--input :clearable="true" v-model="addlogisticForm.arrivalDate" border="none" placeholder="到货日期"></u--input>
					<u-icon @click="arrivalDateShow=true" slot="right" name="arrow-right"></u-icon>
			</u-form-item>
			<u-form-item    label="出库产品"   borderBottom ref="item1">
				 
			</u-form-item>
			<view  style="padding-right: 5xp;margin-bottom: 5px;">
				<uni-table border stripe emptyText="暂无更多数据" >
					<!-- 表头行 -->
					<uni-tr>
						<uni-th align="center" width="70px">产品名称</uni-th>
						<uni-th align="center" width="60px">型号</uni-th>
						<uni-th align="center" width="50px">数量</uni-th>
						 
					</uni-tr>
					<!-- 表格数据行 -->
					<uni-tr v-for="(item,index) in addlogisticForm.logisticsProductList" :key="index">
						<uni-td align="center">{{item.productName}}</uni-td>
						<uni-td align="center">{{item.model}}</uni-td>
						<uni-td align="center">
							<template slot-scope="scope">
								<input @blur="isquantity(item,index)"  v-model="item.quantity" type="text"/>
							</template>
						</uni-td>
						 
					</uni-tr>
				</uni-table>
			</view>
			</u--form>
			<u-datetime-picker :closeOnClickOverlay="true" @close="arrivalDateShow=false"
				    :show="arrivalDateShow" v-model="dateNow" @confirm="arrivalDateConfirm"
				    @cancel="arrivalDateShow=false" mode="date"></u-datetime-picker>
			<u-toast ref="uToast"></u-toast>
			</view>
	</view>
</template>

<script>
	import {addLogisticsApi,getLogisticsListApi,editLogisticsApi,} from '@/api/logistics.js'
	export default {
		data() {
			return {
				addlogisticForm:{
					orderId:'',
					orderProperty:'1',
					logisticsExpenses:'',
					projectName:'',
					orderNo:'',
					projectAddress:'',
					shippingType:'',
					 id:'',
					driverName:'',
					driverTel:'',
					vehicleInformation:'',
					logisticsStatus:'',
					warehouseName:'',
					outboundNo:'',
					returnApplyNo:'',
					type:'',
					logisticsType:'',
					arrivalDate:'',
					logisticsProductList:[],
					consigneeName:'',
					consigneeTel:'',
					outId:''
				},//物流表单
				arrivalDateShow:false,
				dateNow:'',//当前时间
				outInfo:{},//
			};
		},
		onLoad(option) {
			this.dateNow = this.getNowTime()
			 console.log(option);
			 this.outInfo=JSON.parse(decodeURIComponent(option.item))
			this.getlogistic(JSON.parse(decodeURIComponent(option.item)))
		},
		methods:{
			
			//查询物流
			async getlogistic(val){
				let res= await getLogisticsListApi({orderId:this.outInfo.orderId,orderProperty:'3'})
				this.addlogisticForm=res.rows[0]
			},
			// 提交
			async btnOk(){
				await editLogisticsApi(this.addlogisticForm)
				var that=this
				this.$refs.uToast.show({
					type:'success',
					message:'修改成功',
					complete(){
						uni.navigateTo({
							url:"/pages/logistic/addtranferlogistic/addtranferlogistic?id="+that.outInfo.tranid
						})
					}
				})
			},
			// 时间选择器
			arrivalDateConfirm(e) {
			    console.log(e);
			    this.addlogisticForm.arrivalDate = this.getTime(e.value)
			    this.arrivalDateShow = false
			},
			// 获取当前时间
			getNowTime() {
			    var date = new Date()
			    var month = date.getMonth() + 1;
			    var time = date.getFullYear() + "-" + month + "-" + date.getDate();
			    return time;
			},
			// 时间格式化
			getTime(val) {
			    var date = new Date(val);
			    var year = date.getFullYear(); //年 ,从 Date 对象以四位数字返回年份
			    var month = date.getMonth() + 1; //月 ,从 Date 对象返回月份 (0 ~ 11) ,date.getMonth()比实际月份少 1 个月
			    var day = date.getDate(); //日 ,从 Date 对象返回一个月中的某一天 (1 ~ 31)
			    //修改月份格式
			    if (month >= 1 && month <= 9) {
			        month = "0" + month;
			    }
			    //修改日期格式
			    if (day >= 0 && day <= 9) {
			        day = "0" + day;
			    }
			    var currentFormatDate = `${year}-${month}-${day}`;
			    return currentFormatDate
			},
			back(){
				uni.navigateBack({delta:1})
			}
		}
	}
</script>

<style lang="scss">
 .pages{
	   background-color: #fff;
	   .form{
		   background-color: #fff;
		   padding-left: 10px;
	   }
   }
</style>
